<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .div{
            width: 1000px;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
        .a{
            width: 80px;
            margin-left: 50px;
            margin-top: 50px;
        }
        table{
            margin-left: 50px;
            margin-top: 20px;
            color: #fff;
        }
        th,td{
            border: 1px solid black;
            background-color: red;
            width: 100px;
            height: 50px;
        }
        thead tr .i{
            width: 200px;
        }
        .mtk{
            width: 320px;
            height: 100px;
            background-color: bisque;
            position: relative;
            display: none;
            margin-left: 50px;
            margin-top: 50px;
        }
        .cha{
            position: absolute;
            right: 20px;
            top: 10px;
        }
    </style>
</head>
<body>
    <div class="div">
        <button class="a" onclick="f()">添加数据</button>
        <table cellspacing="0">
            <thead>
                <tr>
                    <th class="i">id</th>
                    <th>课程名称</th>
                    <th>所属学院</th>
                    <th>已学会</th>
                </tr>
            </thead>
            <tbody align="center">
                <!-- <tr>
                    <td>79846514568</td>
                    <td>1515</td>
                    <td>8946512</td>
                    <td><span class="sc">删除</span></td>
                </tr> -->
            </tbody>
        </table>
        <div class="mtk">
            <h4>添加数据</h4><span class="cha">×</span>
            课程名称：<input type="text" class="mc"><br>
            所属学院：<input type="text" class="xy"><br>
            <button onclick="tj()">添加</button>
        </div>
    </div>
</body>
</html>
<script>
    var mtk=document.querySelector('.mtk')
    var cha=document.querySelector('.cha')
    var tb=document.querySelector('tbody')
    var mc=document.querySelector('.mc')
    var xy=document.querySelector('.xy')
    var sc=document.querySelector('.sc')
    var id=1;
    function f(){
        mtk.style.display='block'
    }
    cha.onclick= function(){
        mtk.style.display='none'
    }
    function tj(){
        var tr=document.createElement("tr")
        tr.innerHTML=`
                    <td>${id++}</td>
                    <td>${mc.value}</td>
                    <td>${xy.value}</td>
                    <td><button onclick='c(this)'>删除</button></td>
        `;
        tb.appendChild(tr)
        mc.value=''
        xy.value=''
        mtk.style.display='none'
    }
    function c(a){
        tb.removeChild(a.parentNode.parentNode)
    }
</script>